/**
* @Author: Rain
* @Date: 2022/02/11 17:11:49
* @LastEditTime: 2023/09/25 22:08:32
* @Description: Do Something
 */
import request from '@/utils/request'

export function add(data) {
  return request({
    url: 'api/wxUser',
    method: 'post',
    data
  })
}

export function del(ids) {
  return request({
    url: 'api/wxUser/',
    method: 'delete',
    data: ids
  })
}

export function edit(data) {
  return request({
    url: 'api/wxUser',
    method: 'put',
    data
  })
}

export default { add, edit, del }

// 导出用户
export function exportWxUserInfo(data) {
  return request({
    url: '/api/wxUser/download',
    method: 'get',
    responseType: 'blob'
  })
}

// 导出excel文件
export function saveExcelFiles(data, fileName, blobType = 'application/vnd.ms-excel') {
  if (!data) {
    return
  }
  const blob = new Blob([data], {
    type: blobType
  })

  // this.downloadFile(blob, fileName)
  if ('msSaveOrOpenBlob' in navigator) {
    window.navigator.msSaveOrOpenBlob(blob, fileName)
    return
  }
  const url = window.URL.createObjectURL(new Blob([blob]))
  const link = document.createElement('a')
  link.style.display = 'none'
  link.href = url
  link.setAttribute('download', fileName)
  document.body.appendChild(link)
  link.click()
  link.remove()
}
